<template>
  <div class="home">
    <el-container>
      <el-header>
        <span>电商后台管理系统</span>
        <el-button type="info" @click="logout">退出</el-button>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409EFF"
            :default-active="$route.path"
            unique-opened
            router
          >
            <el-submenu
              v-for="menu in navMenu"
              :key="menu.path"
              :index="menu.path"
            >
              <template slot="title">
                <i class="iconfont" :class="`icon-${menu.icon}`"></i>
                <span>{{ menu.name }}</span>
              </template>
              <el-menu-item
                v-for="subMenu in menu.children"
                :key="subMenu.path"
                :index="subMenu.path"
                @click="getTitle(menu.name, subMenu.name)"
              >
                <i class="el-icon-menu"></i>
                {{ subMenu.name }}
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      navMenu: [
        {
          name: "用户管理",
          path: "/users",
          icon: "users",
          children: [{ name: "用户列表", path: "/users" }]
        },
        {
          name: "权限管理",
          path: "/roles",
          icon: "quanxian",
          children: [
            { name: "角色列表", path: "/roles" },
            { name: "权限列表", path: "/power" }
          ]
        },
        {
          name: "商品管理",
          path: "/goods",
          icon: "goods",
          children: [
            { name: "商品列表", path: "/goods" },
            { name: "分类参数", path: "/params" },
            { name: "商品分类", path: "/categories" }
          ]
        },
        {
          name: "订单管理",
          path: "/orders",
          icon: "order",
          children: [{ name: "订单列表", path: "/orders" }]
        },
        {
          name: "数据统计",
          path: "/reports",
          icon: "datamonitoring",
          children: [{ name: "数据报表", path: "/reports" }]
        }
      ]
    };
  },
  methods: {
    logout() {
      this.$router.push("/login")
    },
    getTitle(menu, subMenu) {
      sessionStorage.setItem('menu', menu)
      sessionStorage.setItem('subMenu', subMenu)
    }
  }
};
</script>

<style lang="scss" scoped>
.home .el-container {
  height: 100vh;
}
.el-header {
  background-color: #373d41;
  display: flex;
  align-items: center;
  span {
    flex: 1;
    color: #fff;
    font-size: 22px;
  }
}
.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}
.iconfont {
  padding-right: 20px;
}
.el-main {
  background-color: #eaedf1;
}
</style>
